package com.java.basis.enumtest;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author wangning
 * @create 2021-10-29 14:44
 */
public enum SexEnum {
	BOY("1", "男"),
	Girl("0", "女");
	private String code;
	private String name;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	SexEnum(String code, String name) {
		this.code = code;
		this.name = name;
	}

	public static Optional<SexEnum> fromCode(String code) {
		return Stream.of(SexEnum.values()).filter(item -> item.getCode().equals(code)).findFirst();
	}

}

class TestEnum {
	public static void main(String[] args) {
		System.out.println(SexEnum.fromCode("1"));
		Optional<SexEnum> sexEnum = SexEnum.fromCode("1");

		System.out.println(SexEnum.valueOf("BOY"));


	}
}
